package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.Commom;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;

import com.example.myapplication.ShuJu.LogisticsclassificationBean;
import com.example.myapplication.logisticsinquiry.LogisticscompanyActivity;


import java.util.List;

public class ExpresslistApter extends RecyclerView.Adapter<ExpresslistApter.MyHolder>{
    private Context context;
    private List<LogisticsclassificationBean.DataBean> list;


    public ExpresslistApter(Context context, List<LogisticsclassificationBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ExpresslistApter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_expresslist,null);
        return new ExpresslistApter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ExpresslistApter.MyHolder holder, int position) {
        Glide.with(context).load(TokenBean.IP+list.get(position).getImgUrl()).into(holder.img);
        holder.name.setText(list.get(position).getName());
        holder.li_.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, LogisticscompanyActivity.class);
                intent.putExtra(Commom.LogisticscompanID,String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
    }



    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {

        private final ImageView img;
        private final TextView name;
        private final LinearLayout li_;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.img);
            name = itemView.findViewById(R.id.name);
            li_ = itemView.findViewById(R.id.li_);
        }
    }


}




